import orderApi from '../../../services/order/order';
import commentApi from '../../../services/comment/comment';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchKey: '',
    orders: [],
    currentTeacherId: null,
    comment: ''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.showLoading({
      title: '加载中',
    })
    let userId = getApp().globalData.userInfo.userId
    orderApi.queryOrderByUserId(userId).then(res => {
      console.log(res)
      this.setData({
        orders: res
      })
      wx.hideLoading()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  inputting: function (e) {
    console.log(e);
    this.setData({
      searchKey: e.detail
    });
  },

  showDialog(e) {
    this.setData({
      currentTeacherId: e.currentTarget.dataset.teacherid,
      comment: ''
    })
    this.selectComponent('#graceBottomDialog').open();
  },
  closeDialog() {
    this.selectComponent('#graceBottomDialog').hide();
  },
  bindTextAreaInput: function (e) {
    this.setData({
      comment: e.detail.value
    });
  },

  confirmComment() {
    let comment = {
      objectId: this.data.currentTeacherId,
      content: this.data.comment,
      userId: getApp().globalData.userInfo.userId
    }
    commentApi.create(comment).then(res => {
      this.closeDialog();
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      })
    })
  }
})